/**
  * @file prototipo.cpp
  * @brief Fichero que incluye las definiciones de las funciones miembro de la clase prot.
  *
  */
  
  /* Copyright 2010 Antonio Ruano Cuesta
 *
 * This program is free software: you can redistribute it and/or modify it under 
 * the terms of the GNU General Public License as published by the Free Software 
 * Foundation, either version 3 of the License, or (at your option) any later 
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with 
 * this program. If not, see <http://www.gnu.org/licenses/>
*/

#include <new>
#include "prototipo.h"

using namespace std;

unsigned int prot::n_atrib = 0;

prot::prot()
{
	clase=0;
	atributos=0;
}

prot::prot(unsigned int clas, int n_atributos)
{
	if (n_atributos > 0 && clas >= 0){
		clase=clas;
		n_atrib=n_atributos;
		atributos = new (nothrow) float [n_atributos];
	}
	else
		atributos = 0;
}

prot::prot(const prot &prt)
{
	clase=prt.clase;
	n_atrib=prt.n_atrib;
	
	atributos = new (nothrow) float [n_atrib];

	for (unsigned int i = 0 ; i<n_atrib ; i++)
		atributos[i]=prt.atributos[i];
}

prot::~prot()
{
	delete [] atributos;
}

prot& prot::operator= (const prot &prototipo)
{
	
	if(this != &prototipo){
	
		if (n_atrib > 0)
			delete [] atributos;
		

		n_atrib=prototipo.n_atrib;
		clase=prototipo.clase;

		atributos = new (nothrow) float [n_atrib];

		for(unsigned int i = 0 ; i < n_atrib ; ++i)
			atributos[i]=prototipo.atributos[i];
	}

	return *this;
}

void prot::set_atrib (float atr, int pos)
{
	atributos[pos]=atr;
}

float prot::get_atrib (int pos) const
{
	return atributos[pos];
}

unsigned int prot::get_clase () const
{
	return clase;
}

void prot::set_clase (unsigned int cls)
{
	clase=cls;
}

unsigned int & prot::get_natr()
{
	return n_atrib;
}
